<template>
  <div class="holesTable">
    <table cellspacing="0"
      border-collapse="0">
      <template
        v-for="(item, index) in tableData">
        <tr align="center" v-if="index === 0"
          :key="index">
          <td class="label"></td>
          <td v-for="head in 12" :key="head"
            class="label">
            {{head}}
          </td>
        </tr>
      </template>
      <tr align="center"
        v-for="(item, index) in tableData"
        :key="index">
        <template v-if="item.row">
          <td class="label">{{item.row}}</td>
          <td v-for="(head, i) in 12"
            :key="head">
            <div 
              class="text_item"
              @dblclick="handleChange(item, i+1)"
              :class="{
                active: getActiveName(`${item.row}${i+1}`),
              }">
              {{ getHoleValue(`${item.row}${i+1}`) }}{{Symbol}}
            </div>
          </td>
        </template>
      </tr>
    </table>
  </div>
</template>

<script>

export default {
  data() {
    return {
      tableData: [
        {
          row: "A",
          content: {},
        },
        {
          row: "B",
          content: {},
        },
        {
          row: "C",
          content: {},
        },
        {
          row: "D",
          content: {},
        },
        {
          row: "E",
          content: {},
        },
        {
          row: "F",
          content: {},
        },
        {
          row: "G",
          content: {},
        },
        {
          row: "H",
          content: {},
        },
      ],
    };
  },
  props: {
    // 表格数据
    value: {
      type: Array,
      default: () => []
    },
    // 是否拼接特殊单位
    Symbol: {
      type: String,
      default: ''
    },
    isDeatailPage: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 判断是否选中
    getActiveName(hole) {
      const result = this.value.find(item => item.hole === hole) || {}
      return !result.editValue || false
    },
    // 获取孔值
    getHoleValue(hole) {
      const result = this.value.find(item => item.hole === hole) || {}
      return result.editValue || ''
    },
    // 双击
    handleChange(item, index) {
      if(this.isDeatailPage) return
      const isExist = this.value.some(hole => hole.hole === item.row + index)
      if(!isExist) return
      this.$emit('handleChange', item.row + index)
    }
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-input__inner {
    width: 100%;
    height: 40px;
    outline-color: #409eff;
    padding: 0 2px;
    border-radius: inherit;
    text-align: center;
  }
  .el-input.is-disabled .el-input__inner {
    background-color: #dbf3ff;
  }
}
.holesTable {
  width: 100%;
  table {
    border-width: 0.1px;
    border-color: #b9cede;
    tr {
      .label {
        min-width: 60px;
        height: 40px;
        background-color: #409eff;
        color: #fff;
      }
      td {
        box-sizing: border-box;
        width: 30px;
        border-color: #b9cede;
        border: 1px solid #b9cede;
        input {
          width: 100%;
          height: 38px;
          border: none;
          outline-color: #409eff;
        }
        .text_item {
          cursor: pointer;
          height: 30px;
          line-height: 30px;
          color: #000;
        }
        .text_item:hover {
          background-color: #89afe0;
          color: #fff;
        }
      }
    }
  }
  .active {
    background-color: #89afe0 !important;
    height: 40px;
    line-height: 40px;
  }
}
</style>